package com.lyl.myaiagent.optimize.filtering_retrieval;

import org.springframework.ai.chat.client.advisor.RetrievalAugmentationAdvisor;
import org.springframework.ai.chat.client.advisor.api.Advisor;
import org.springframework.ai.rag.retrieval.search.VectorStoreDocumentRetriever;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.ai.vectorstore.filter.Filter;
import org.springframework.ai.vectorstore.filter.FilterExpressionBuilder;

/**
 * @author lyl
 * @version 1.0
 * @CreateTime: 2025-08-19
 */
public class CustomerRetrieverAdvisorFactory {

    public static Advisor createCustomerRetrieverAdvisor(VectorStore vectorStore, String filter) {
        Filter.Expression expression = new FilterExpressionBuilder()
                .eq("tag", filter)
                .build();
        VectorStoreDocumentRetriever documentRetriever = VectorStoreDocumentRetriever.builder()
                .vectorStore(vectorStore)
                .similarityThreshold(0.75)
                .topK(3)
                .filterExpression(expression)
                .build();

        return RetrievalAugmentationAdvisor.builder()
                .documentRetriever(documentRetriever)
                .build();
    }

}
